**2000 **No GunOwner Question
use "anes2000TS.dta", clear

gen gunc=V000728
recode gunc 1=1 3=0 5=0 8=. 9=. 0=.

gen gunc3=V000728
recode gunc3 1=3 3=1 5=2 8=. 9=. 0=.


gen trust=V001534
recode trust 1=3 2=2 3=1 4=0  8=. 9=.
gen trust01=trust
recode trust01 3=1 2=.6667 1=.3333 0=0

gen trustv=1

gen pid7=V000523
recode pid7 0=1 1=2 2=3 3=4 4=5 5=6 6=7 7=4 8=4 9=.
gen pid701=(pid7-1)/6

gen demstr=pid7
recode demstr 1=3 2=2 3=1 4=0 5=0 6=0 7=0
gen demstr01=demstr
recode demstr01 3=1 2=.6667 1=.3333 0=0
gen repstr=pid7
recode repstr 1=0 2=0 3=0 4=0 5=1 6=2 7=3
gen repstr01=repstr
recode repstr01 3=1 2=.6667 1=.3333 0=0

gen age=V000908
recode age 0=. 90/99=90
gen age01=(age-18)/72

gen education=V000913
recode education 1=0 2=0 3=1 4=1 5=1 6=2 7=3 9=.

gen highschool=education
recode highschool 0=0 1=1 2=0 3=0

gen college=education
recode college 0=0 1=0 2=1 3=0

gen graduate=education
recode graduate 0=0 1=0 2=0 3=1

gen female=V001029
recode female 1=0 2=1

gen hispanic=. if V001006a==0
replace hispanic=0 if V001006a==10
replace hispanic=0 if V001006a==20
replace hispanic=0 if V001006a==30
replace hispanic=1 if V001006a==40
replace hispanic=0 if V001006a==50
replace hispanic=0 if V001006a==60
replace hispanic=0 if V001006a==75
replace hispanic=0 if V001006a==76
replace hispanic=0 if V001006a==79
replace hispanic=0 if V001006a==80
replace hispanic=0 if V001006a==90
replace hispanic=. if V001006a==98
replace hispanic=. if V001006a==99
replace hispanic=1 if V001006b==40

gen white=. if V001006a==0
replace white=0 if V001006a==10
replace white=0 if V001006a==20
replace white=0 if V001006a==30
replace white=0 if V001006a==40
replace white=1 if V001006a==50
replace white=0 if V001006a==60
replace white=0 if V001006a==75
replace white=0 if V001006a==76
replace white=0 if V001006a==79
replace white=0 if V001006a==80
replace white=0 if V001006a==90
replace white=. if V001006a==98
replace white=. if V001006a==99
replace white=1 if V001006b==50

gen black=. if V001006a==0
replace black=1 if V001006a==10
replace black=0 if V001006a==20
replace black=0 if V001006a==30
replace black=0 if V001006a==40
replace black=0 if V001006a==50
replace black=0 if V001006a==60
replace black=0 if V001006a==75
replace black=0 if V001006a==76
replace black=0 if V001006a==79
replace black=0 if V001006a==80
replace black=0 if V001006a==90
replace white=. if V001006a==98
replace white=. if V001006a==99
replace black=0 if V001006b==10


gen income=V000997
recode income 0=. 98=. 99=.
gen incomecat=income
recode incomecat 1/2=0 3/4=1 5=2 6=3 7/22=4
gen income01=incomecat/4

gen ideology=V000447
recode ideology 0=. 7=. 8=. 1=1 3=2 5=3
gen ideology01=(ideology-1)/2


gen prezapprove=V000341
recode prezapprove 1=4 2=3 4=1 5=0 8=. 9=.
gen prezapp01=prezapprove/4

gen congapprove=V000358
recode congapprove 1=4 2=3 4=1 5=0 8=. 9=.
gen congapp01=congapprove/4


gen rr1=V001508 if V001508<8
recode rr1 5=1 4=2 3=3 2=4 1=5
gen rr2=V001509 if V001509<8
gen rr3=V001510 if V001510<8
gen rr4=V001511 if V001511<8
recode rr4 5=1 4=2 3=3 2=4 1=5

recode rr1 0=.
recode rr2 0=.
recode rr3 0=.
recode rr4 0=.

replace rr1=(rr1-1)/4
replace rr2=(rr2-1)/4
replace rr3=(rr3-1)/4
replace rr4=(rr4-1)/4

gen rrtot=(rr1+rr2+rr3+rr4)/4



gen anesweight=V000002 

keep gunc gunc3 trust01 trustv pid701 demstr01 repstr01 demstr repstr age01 highschool college graduate female hispanic white black income01 ideology01  prezapp01 congapp01 rrtot anesweight
save "Recode2000.dta", replace


**2004*
use "anes2004TS.dta", clear

gen gunc=V043188 
recode gunc 1=1 3=0 5=0 8=. 9=.

gen gunc3=V043188 
recode gunc3 1=3 3=1 5=2 8=. 9=.


gen trust=V045197
recode trust 1=3 2=2 3=1 4=0  8=. 9=.
gen trust01=trust
recode trust01 3=1 2=.6667 1=.3333 0=0

gen trustv=1

gen pid7=V043116
recode pid7 0=1 1=2 2=3 3=4 4=5 5=6 6=7 7=4 8=. 9=.
gen pid701=(pid7-1)/6

gen demstr=pid7
recode demstr 1=3 2=2 3=1 4=0 5=0 6=0 7=0
gen demstr01=demstr
recode demstr01 3=1 2=.6667 1=.3333 0=0

gen repstr=pid7
recode repstr 1=0 2=0 3=0 4=0 5=1 6=2 7=3
gen repstr01=repstr
recode repstr01 3=1 2=.6667 1=.3333 0=0

gen education=V043254 
recode education 0=0 1=0 2=0 3=1 4=1 5=1 6=2 7=3  8=. 9=.

gen highschool=education
recode highschool 0=0 1=1 2=0 3=0

gen college=education
recode college 0=0 1=0 2=1 3=0

gen graduate=education
recode graduate 0=0 1=0 2=0 3=1

gen female=V041109a 
recode female 1=0 2=1 

gen income=V043293x 
recode income 88=. 89=. 0=.
gen incomecat=income
recode incomecat 1/9=0 10/13=1 14/17=2 18/20=3 21/23=4
gen income01=incomecat/4

gen age=2004-V043249a
replace age=. if age<0
gen age01=(age-18)/72

gen hispanic=V043299
recode hispanic 10=0 14=1 15=0 20=0 23=0 25=0 30=0 35=0 40=1 45=1 50=0 70=0 88=. 89=.

gen white=V043299
recode white 10=0 14=0 15=1 20=0 23=0 25=1 30=0 35=1 40=0 45=1 50=1 70=0 88=. 89=.

gen black=V043299
recode black 10=1 14=1 15=1 20=0 23=0 25=0 30=0 35=0 40=0 45=0 50=0 70=0 88=. 89=.

gen gunowner=V043195 
recode gunowner 1=1 5=0   8=. 9=.

gen ideology=V043085
recode ideology 80=. 88=. 89=.
gen ideology01=(ideology-1)/6

gen prezapprove=V043025
recode prezapprove 1=4 2=3 4=1 5=0 8=. 9=.
gen prezapp01=prezapprove/4

gen congapprove=V043037 
recode congapprove 1=4 2=3 4=1 5=0 8=. 9=.
gen congapp01=congapprove/4


gen rr1=V045193 if V045193<8
recode rr1 5=1 4=2 3=3 2=4 1=5
gen rr2=V045194 if V045194<8
gen rr3=V045195 if V045195<8
gen rr4=V045196 if V045196<8
recode rr4 5=1 4=2 3=3 2=4 1=5


replace rr1=(rr1-1)/4
replace rr2=(rr2-1)/4
replace rr3=(rr3-1)/4
replace rr4=(rr4-1)/4

gen rrtot=(rr1+rr2+rr3+rr4)/4



gen anesweight=V040101 

keep gunc gunc3 trust01 trustv pid701 demstr01 repstr01 demstr repstr age01 gunowner highschool college graduate female hispanic white black income01 ideology01 prezapp01 congapp01 rrtot anesweight
save "Recode2004.dta", replace

**2008**
use "anes_timeseries_2008.dta", clear

gen gunc=V083164
recode gunc 1=1 3=0 5=0 -8=. -9=.

gen gunc3=V083164
recode gunc3 1=3 3=1 5=2 -8=. -9=.


gen trust1=V085147a
recode trust1  -9=. -8=. -2=. -1=. 1=1 2=.6667 3=.3333 4=0

gen trust2=V085147b
recode trust2  -9=. -8=. -2=. -1=. 1=1 2=.6667 3=.5 4=.3333 5=0

gen trustv=1 if trust1!=.
replace trustv=0 if trust2!=.

gen trustall=trust1 if trust1!=.
replace trustall=trust2 if trust2!=.
gen trust01=trustall

gen pid7=V083098x 
recode pid7 0=1 1=2 2=3 3=4 4=5 5=6 6=7 7=4 8=. 9=. -1=.
gen pid701=(pid7-1)/6

gen demstr=pid7
recode demstr 1=3 2=2 3=1 4=0 5=0 6=0 7=0
gen demstr01=demstr
recode demstr01 3=1 2=.6667 1=.3333 0=0

gen repstr=pid7
recode repstr 1=0 2=0 3=0 4=0 5=1 6=2 7=3
gen repstr01=repstr
recode repstr01 3=1 2=.6667 1=.3333 0=0

gen female=V081101
recode female 1=0 2=1

gen age=V081104
recode age -8=. -9=. 17=18
gen age01=(age-18)/72

gen hispanic=1 if V083251a==40
replace hispanic=1  if V083251b==40
replace hispanic=0 if hispanic==.
replace hispanic=. if V083251a==-8
replace hispanic=. if V083251a==-9

gen white=1 if V083251a==50
replace white=1  if V083251b==50
replace white=0 if white==.
replace white=. if V083251a==-8
replace white=. if V083251a==-9

gen black=1 if V083251a==10
replace black=1  if V083251b==10
replace black=0 if black==.
replace black=. if V083251a==-8
replace black=. if V083251a==-9

gen education=V083218x
recode education 0=0 1=0 2=0 3=1 4=1 5=1 6=2 7=3 -8=. -9=.

gen highschool=education
recode highschool 0=0 1=1 2=0 3=0

gen college=education
recode college 0=0 1=0 2=1 3=0

gen graduate=education
recode graduate 0=0 1=0 2=0 3=1

gen gunowner=V083165
recode gunowner 1=1 5=0   8=. 9=. -9=. -8=.

gen income=V083248x
recode income -1=. -8=. -9=.
gen incomecat=income
recode incomecat 1/7=0 8/12=1 13/16=2 17/18=3 19/25=4
gen income01=incomecat/4

gen ideology=V083069 if V083069>0
gen ideology01=(ideology-1)/6

gen prezapprove=V083028x
recode prezapprove 1=4 2=3 4=1 5=0 -8=. -9=.
gen prezapp01=prezapprove/4

gen congapprove=V083035x
recode congapprove 1=4 2=3 4=1 5=0 -8=. -9=.
gen congapp01=congapprove/4

gen anesweight=V080101a

 

gen rr1=V085143 if V085143>0
recode rr1 5=1 4=2 3=3 2=4 1=5
gen rr2=V085144 if V085144>0
gen rr3=V085145 if V085145>0
gen rr4=V085146 if V085146>0
recode rr4 5=1 4=2 3=3 2=4 1=5

replace rr1=(rr1-1)/4
replace rr2=(rr2-1)/4
replace rr3=(rr3-1)/4
replace rr4=(rr4-1)/4

gen rrtot=(rr1+rr2+rr3+rr4)/4

keep gunc gunc3 trust01 pid701  demstr01 repstr01 demstr repstr age01 gunowner highschool college graduate female hispanic white black income01 ideology01 prezapp01 congapp01 rrtot anesweight trustv
save "Recode2008.dta", replace


**2012
use "anes_timeseries_2012.dta", clear

gen gunc=gun_control
recode gunc -8=. -9=. 1=1 2=0 3=0

gen gunc3=gun_control
recode gunc3 1=3 2=1 3=2 -8=. -9=.


gen gunowner=owngun_owngun
recode gunowner 1=1 2=0  -8=. -9=. 

gen trust1=trustgov_trustgrev if trustgov_trustgrev>0
recode trust1 1=1 2=.6667 3=.5 4=.3333 5=0

gen trust2=trustgov_trustgstd if trustgov_trustgstd>0
recode trust2 1=1 2=.6667 3=.3333 4=0

gen trustv=0 if trust1!=.
replace trustv=1 if trust2!=.

gen trust01=trust1 if trust1!=.
replace trust01=trust2 if trust2!=.

gen pid7=pid_x
recode pid7 -2=.
gen pid701=(pid7-1)/6

gen demstr=pid7
recode demstr 1=3 2=2 3=1 4=0 5=0 6=0 7=0
gen demstr01=demstr
recode demstr01 3=1 2=.6667 1=.3333 0=0

gen repstr=pid7
recode repstr 1=0 2=0 3=0 4=0 5=1 6=2 7=3
gen repstr01=repstr
recode repstr01 3=1 2=.6667 1=.3333 0=0


gen age=dem_age_r_x if dem_age_r_x>=18
gen age01=(age-18)/72

gen education=dem_edu
recode education -9=. 1=0 2=0 3=0 4=0 5=0 6=0 7=0 8=0 9=1 10=1 11=1 12=1 13=2 14=3 15=3 16=3 95=.


gen highschool=education
recode highschool 0=0 1=1 2=0 3=0

gen college=education
recode college 0=0 1=0 2=1 3=0

gen graduate=education
recode graduate 0=0 1=0 2=0 3=1

gen female1=profile_gender
recode female1 2=1 1=0 -1=.

gen female2=iwrdesc_pre_gender
recode female2  2=1 1=0 -1=. -2=. -9=.

gen female=female1 if female1!=.
replace female=female2 if female2!=.

gen hispanic=1 if dem_hisp==1
replace hispanic=0 if dem_hisp==2


gen white=1 if dem_racecps_white==1
replace white=0 if dem_racecps_white==0

gen black=1 if dem_racecps_black==1
replace black=0 if dem_racecps_black==0

gen income=inc_incgroup_pre if inc_incgroup_pre>0
gen incomecat=income
recode incomecat 1/5=0 2/11=1 12/16=2 17/21=3 22/28=4
gen income01=incomecat/4

gen ideology=libcpre_self if libcpre_self>0
gen ideology01=(ideology-1)/6


gen prezapprove=presapp_job_x
recode prezapprove 1=4 2=3 4=1 5=0 -8=. -9=.
gen prezapp01=prezapprove/4

gen congapprove=congapp_job_x
recode congapprove 1=4 2=3 4=1 5=0 -8=. -9=.
gen congapp01=congapprove/4

gen rr1=resent_w if resent_w>0
recode rr1 5=1 4=2 3=3 2=4 1=5
gen rr2=resent_s if resent_s>0
gen rr3=resent_d if resent_d>0
gen rr4=resent_t if resent_t>0
recode rr4 5=1 4=2 3=3 2=4 1=5

replace rr1=(rr1-1)/4
replace rr2=(rr2-1)/4
replace rr3=(rr3-1)/4
replace rr4=(rr4-1)/4

gen rrtot=(rr1+rr2+rr3+rr4)/4


gen anesweight=weight_full

save "Recode2012.dta", replace


**2016
use "anes_timeseries_2016.dta", clear

**DEMOGRAPHICS
gen FTF=V160501
recode FTF 2=0

gen age=V161267x
recode age -1=. 1=1 2=1 3=1 4=2 5=2 6=3 7=3 8=4 9=4 10=5 11=5 12=6 13=6
gen age01=(age-1)/5

gen education=V161270 if V161270>0
recode education 90=. 95=.
recode education 1=1 2=1 3=1 4=1 5=1 6=1 7=1 8=1 9=2 10=3 11=3 12=3 13=4 14=5 15=5 16=5
gen education01=(education-1)/4

gen highschool=V161270 if V161270>0
recode highschool 1=0 2=0 3=0 4=0 5=0 6=0 7=0 8=0 9=1 10=1 11=1 12=1 13=0 14=0 15=0 16=0 90=1 95=.

gen college=V161270 if V161270>0
recode college 1=0 2=0 3=0 4=0 5=0 6=0 7=0 8=0 9=0 10=0 11=0 12=0 13=1 14=0 15=0 16=0 90=0 95=.

gen graduate=V161270 if V161270>0
recode graduate 1=0 2=0 3=0 4=0 5=0 6=0 7=0 8=0 9=0 10=0 11=0 12=0 13=0 14=1 15=1 16=1 90=0 95=.

gen white=V161310x
recode white -9=. 1=1 2=0 3=0 4=0 5=0 6=0

gen black=V161310x
recode black -9=. 1=0 2=1 3=0 4=0 5=0 6=0

gen hispanic=V161310x
recode hispanic -9=. 1=0 2=0 3=0 4=0 5=1 6=0

gen female=V161342
recode female -9=. 1=0 2=1 3=.

gen income01=V161361x if V161361x>0
recode income01 1/6=1 7/13=2 14/18=3 19/23=4 24/28=5
replace income01=(income-1)/4


**Partisanship/Ideology
gen pid7=V161158x if V161158x>0
gen pid701=(pid7-1)/6


gen demstr=pid7
recode demstr 1=3 2=2 3=1 4=0 5=0 6=0 7=0
gen demstr01=demstr
recode demstr01 3=1 2=.6667 1=.3333 0=0

gen repstr=pid7
recode repstr 1=0 2=0 3=0 4=0 5=1 6=2 7=3
gen repstr01=repstr
recode repstr01 3=1 2=.6667 1=.3333 0=0

gen ideology=V162171 if V162171>0
recode ideology 99=.
gen ideology01=(ideology-1)/6

gen liberal=ideology
recode liberal  1=3 2=2 3=1 4=0 5=0 6=0 7=0

gen conservative=ideology
recode conservative  1=0 2=0 3=0 4=0 5=1 6=2 7=3


**GUN CONTROL
gen gunc=V161187
recode gunc -9=. -8=. 1=1 2=0 3=0

gen gunc3=V161187
recode gunc3 1=3 2=1 3=2 -9=. -8=. 


gen gunsowned=V161496 if V161496>=0
gen lngunsowned=ln(gunsowned)

gen gunowner=gunsowned
recode gunowner 0=0 1/100=1

**TRUST
gen trust=V161215
recode trust -9=. -8=. 1=4 2=3 3=2 4=1 5=0
gen trust01=trust
recode  trust01  4=1 3=.6667 2=.5 1=.3333 0=0

gen trustv=0

gen prezapprove=V161082x
recode prezapprove 1=4 2=3 4=1 5=0 -1=.
gen prezapp01=prezapprove/4

gen congapprove=V161080x
recode congapprove 1=4 2=3 4=1 5=0 -1=.
gen congapp01=congapprove/4

gen rr1=V162211 if V162211>0
recode rr1 5=1 4=2 3=3 2=4 1=5
gen rr2=V162212 if V162212>0
gen rr3=V162213 if V162213>0
gen rr4=V162214 if V162214>0
recode rr4 5=1 4=2 3=3 2=4 1=5

replace rr1=(rr1-1)/4
replace rr2=(rr2-1)/4
replace rr3=(rr3-1)/4
replace rr4=(rr4-1)/4

gen rrtot=(rr1+rr2+rr3+rr4)/4

   

gen anesweight=V160101

keep gunc gunc3 trust01 trustv pid701  demstr01 repstr01 demstr repstr age01 gunowner highschool college graduate female hispanic white black income01 ideology01   prezapp01 congapp01 anesweight rrtot
save "Recode2016.dta", replace

gen year=1996
append using "Recode2000.dta"
replace year=2000 if year==.
append using "Recode2004.dta"
replace year=2004 if year==.
append using "Recode2008.dta"
replace year=2008 if year==.
append using "Recode2012.dta"
replace year=2012 if year==.
append using "Recode2016.dta"
replace year=2016 if year==.

gen yearfactor=0 if year==1996
replace yearfactor=1 if year==2000
replace yearfactor=2 if year==2004
replace yearfactor=3 if year==2008
replace yearfactor=4 if year==2012
replace yearfactor=5 if year==2016


cls
***TABLE 1 Models
**Margins produce values for FIGURE 3 
***2000
*logit gunc c.trust01 c.ideology01 pid701 c.rrtot c.congapp01 c.prezapp01 i.highschool i.college i.graduate i.female c.age01 i.hispanic i.white i.black c.income01 [pweight=anesweight] if year==2000
*estat ic
quiet logit gunc c.trust01##c.ideology01 pid701 c.rrtot c.congapp01 c.prezapp01 i.highschool i.college i.graduate i.female c.age01 i.hispanic i.white i.black c.income01 [pweight=anesweight] if year==2000
*estat ic
margins, dydx(trust) at(ideology01=(0(.1666666666666666)1))

***2004
*logit gunc c.trust01 c.ideology01 pid701 c.rrtot c.congapp01 c.prezapp01 i.highschool i.college i.graduate i.female c.age01 i.hispanic i.white i.black c.income01 [pweight=anesweight] if year==2004
*estat ic
quiet logit gunc c.trust01##c.ideology01 pid701 c.rrtot c.congapp01 c.prezapp01 i.highschool i.college i.graduate i.female c.age01 i.hispanic i.white i.black c.income01 [pweight=anesweight] if year==2004
*estat ic
margins, dydx(trust) at(ideology01=(0(.1666666666666666)1))

***2008
*logit gunc c.trust01 c.ideology01 pid701 c.rrtot c.congapp01 c.prezapp01 i.highschool i.college i.graduate i.female c.age01 i.hispanic i.white i.black c.income01 [pweight=anesweight] if year==2008
*estat ic
quiet logit gunc c.trust01##c.ideology01 pid701 c.rrtot c.congapp01 c.prezapp01 i.highschool i.college i.graduate i.female c.age01 i.hispanic i.white i.black c.income01 [pweight=anesweight] if year==2008
*estat ic
margins, dydx(trust) at(ideology01=(0(.1666666666666666)1))

***2012
*logit gunc c.trust01 c.ideology01 pid701 c.rrtot c.congapp01 c.prezapp01 i.highschool i.college i.graduate i.female c.age01 i.hispanic i.white i.black c.income01 [pweight=anesweight] if year==2012
*estat ic
quiet logit gunc c.trust01##c.ideology01 pid701 c.rrtot c.congapp01 c.prezapp01 i.highschool i.college i.graduate i.female c.age01 i.hispanic i.white i.black c.income01 [pweight=anesweight] if year==2012
*estat ic
margins, dydx(trust) at(ideology01=(0(.1666666666666666)1))

***2016
*logit gunc c.trust01 c.ideology01 pid701 c.rrtot c.congapp01 c.prezapp01 i.highschool i.college i.graduate i.female c.age01 i.hispanic i.white i.black c.income01 [pweight=anesweight] if year==2016
*estat ic
quiet logit gunc c.trust01##c.ideology01 pid701 c.rrtot c.congapp01 c.prezapp01 i.highschool i.college i.graduate i.female c.age01 i.hispanic i.white i.black c.income01 [pweight=anesweight] if year==2016
*estat ic
margins, dydx(trust) at(ideology01=(0(.1666666666666666)1))

**All Years
logit gunc c.trust01##c.ideology01 C.yearfactor pid701 c.rrtot c.congapp01 c.prezapp01 i.highschool i.college i.graduate i.female c.age01 i.hispanic i.white i.black c.income01 [pweight=anesweight] if year>1996
estat ic
quiet logit gunc c.trust01##c.ideology01##c.yearfactor pid701 c.rrtot c.congapp01 c.prezapp01 i.highschool i.college i.graduate i.female c.age01 i.hispanic i.white i.black c.income01 [pweight=anesweight] if year>1996
estat ic
margins, dydx(trust) at(ideology01=(0(.1666666666666666)1) yearfactor=1)
margins, dydx(trust) at(ideology01=(0(.1666666666666666)1) yearfactor=5)



